<?php
/**
 * Geocontexter
 * @link http://code.google.com/p/geocontexter/
 * @package Geocontexter
 */

/**
 * Admin index controller
 *
 *
 * @package Geocontexter
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @author Armand Turpel <geocontexter@gmail.com>
 * @version $Rev$ / $LastChangedDate$ / $LastChangedBy$
 */

namespace Gospecies\Controller;

use Zend\View\Model\JsonModel;
use Gospecies\Controller\AbstractJsonController;


class JsonTaxonSearchController extends AbstractJsonController
{

    protected function init($controller)
    {

    }

    public function indexAction()
    {
        $term       = $this->params()->fromQuery('term',false);
        $id_project = $this->params()->fromQuery('id_project',false);

        $ItemSearch = $this->CoreModel('ItemSearch', 'Gospecies');

        $params  = array('search'     => $term,
                         'id_project' => $id_project,
                         'limit'      => array(20,0));

        try {

          $result  = $ItemSearch->run( $params );

          return new JsonModel($result);

        } catch (\Exception $e) {

          $this->default_error = "Error\n File: " . __file__ . "\nLine: " . __line__ . "\nError: " . $e->getErrorString();

          return new JsonModel(array('error' => $this->default_error));

        }
    }
}
